package com.hxd.otc.module.convenience.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.enums.ConvenienceBusinessTypeEnum;
import com.hxd.otc.module.convenience.bean.NorGoodsBean;
import com.hxd.otc.module.convenience.bean.RefuelingServiceBean;
import com.hxd.otc.module.convenience.contract.VideoServiceRechargeContract;
import com.hxd.otc.module.convenience.model.ConvenienceModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * Created by lzy on 2018/12/14 0014.
 * description ${视频服务充值Presenter}
 */
public class VideoServiceRechargePresenter extends BasePresenter<VideoServiceRechargeContract.IView> implements VideoServiceRechargeContract.IPresenter {
    private final ConvenienceModel mConvenienceModel;
    private RefuelingServiceBean mRefuelingServiceBean;
    private ConvenienceBusinessTypeEnum mBusinessType;

    public VideoServiceRechargePresenter(VideoServiceRechargeContract.IView iView) {
        super(iView);
        mConvenienceModel = ConvenienceModel.getInstance();
    }

    @Override
    public void setRefuelingServiceBean(RefuelingServiceBean refuelingServiceBean) {
        mRefuelingServiceBean = refuelingServiceBean;
    }

    @Override
    public void getVideoTypeData() {
        mConvenienceModel.getModuleList(mRefuelingServiceBean.getId(), new BaseObserver<ArrayList<RefuelingServiceBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<RefuelingServiceBean> refuelingServiceBeans) {
                mView.getVideoTypeDataSuccess(refuelingServiceBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ArrayList<RefuelingServiceBean>>>bindAutoDispose());
    }

    @Override
    public void getVideoGoodsData(final String moduleId) {
        mConvenienceModel.getGoodsList(moduleId, new BaseObserver<ArrayList<NorGoodsBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<NorGoodsBean> norGoodsBeans) {
                mView.getVideoGoodsDataSuccess(moduleId, norGoodsBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getVideoGoodsDataFail(moduleId, errMessage);
            }
        }, mView.<BaseBean<ArrayList<NorGoodsBean>>>bindAutoDispose());
    }

    @Override
    public void setBusinessType(ConvenienceBusinessTypeEnum businessType) {
        mBusinessType = businessType;
    }

    @Override
    public ConvenienceBusinessTypeEnum getBusinessType() {
        return mBusinessType;
    }
}
